package com.headStorm.concurrent.manyThread;

import java.util.Date;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class MainThreadBlocking {

    public static final BlockingQueue<String> queue = new ArrayBlockingQueue<String>(10);

    public static void main(String[] args) {
        ExecutorService cachedThreadPool = Executors.newFixedThreadPool(2);
        cachedThreadPool.execute(new Runnable() {
            @Override
                public void run() {
                while (true){
                    try {
                        queue.put(new Date().toGMTString());
                        System.out.println("put");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
        cachedThreadPool.execute(new Runnable() {
            @Override
            public void run() {
                while (true){
                    try {
                        System.out.println(queue.take());
                        System.out.println("take");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });
    }
}
